package com.ccr.roeun.moneymanager.app;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ccr.roeun.moneymanager.core.RowItem;

import java.util.List;

public class CustomAdapter extends BaseAdapter {


    Context content;
    List<RowItem> rowItem;

    public CustomAdapter(Context content,List<RowItem> rowItem) {
        this.content = content;
        this.rowItem = rowItem;
    }

    @Override
    public int getCount() {
        return rowItem.size();
    }

    @Override
    public Object getItem(int position) {
        return rowItem.get(position);
    }

    @Override
    public long getItemId(int position) {
        return rowItem.indexOf(getItem(position));
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {

        if (view == null) {
            LayoutInflater mLayoutInflater = (LayoutInflater) content.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            view = mLayoutInflater.inflate(R.layout.list_item, null);
        }
        ImageView imageIcon = (ImageView) view.findViewById(R.id.icon);
        TextView txtTitle = (TextView) view.findViewById(R.id.title);
        RowItem rowPos = rowItem.get(position);
        imageIcon.setImageResource(rowPos.getIcon());
        txtTitle.setText(rowPos.getTitle());
        return view;
    }
}
